package demoMod.invincibleOne.powers;

import com.badlogic.gdx.math.Vector2;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.SpawnMonsterAction;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.monsters.exordium.AcidSlime_M;
import com.megacrit.cardcrawl.monsters.exordium.AcidSlime_S;
import com.megacrit.cardcrawl.monsters.exordium.SpikeSlime_M;
import com.megacrit.cardcrawl.monsters.exordium.SpikeSlime_S;
import com.megacrit.cardcrawl.powers.AbstractPower;
import demoMod.invincibleOne.InvincibleOneMod;

public class CrowdTacticsPower extends AbstractPower {
    public static final String POWER_ID = InvincibleOneMod.makeID("CrowdTacticsPower");
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESC = powerStrings.DESCRIPTIONS;
    private final boolean upgraded;

    public CrowdTacticsPower(AbstractCreature owner, int amount, boolean upgraded) {
        this.owner = owner;
        this.ID = POWER_ID;
        this.name = NAME;
        this.upgraded = upgraded;
        if (upgraded) {
            this.ID += "+";
            this.name += "+";
        }
        this.amount = amount;
        this.updateDescription();
        loadRegion("painfulStabs");
    }

    @Override
    public void updateDescription() {
        if (upgraded) {
            this.description = String.format(DESC[1], this.amount);
        } else {
            this.description = String.format(DESC[0], this.amount);
        }
    }

    @Override
    public void onDeath() {
        if (AbstractDungeon.getMonsters().areMonstersBasicallyDead()) {
            return;
        }
        Vector2 vector2 = new Vector2(120.0F * Settings.scale, 0.0F);
        for (int i=0;i<this.amount;i++) {
            AbstractMonster slime;
            if (upgraded) {
                if (AbstractDungeon.cardRandomRng.randomBoolean()) {
                    slime = new AcidSlime_M(0.0F, 0.0F);
                } else {
                    slime = new SpikeSlime_M(0.0F, 0.0F);
                }
            } else {
                if (AbstractDungeon.cardRandomRng.randomBoolean()) {
                    slime = new AcidSlime_S(0.0F, 0.0F, 0);
                } else {
                    slime = new SpikeSlime_S(0.0F, 0.0F, 0);
                }
            }
            slime.drawX = owner.drawX - vector2.x;
            slime.drawY = owner.drawY - vector2.y;
            addToBot(new SpawnMonsterAction(slime, true));
            addToBot(new AbstractGameAction() {
                @Override
                public void update() {
                    slime.createIntent();
                    isDone = true;
                }
            });
            vector2.rotate(45.0F);
        }
    }
}
